/*
 * mcg.c
 *
 */
#include "derivative.h" /* include peripheral declarations */

/*
 *	This method configures the Multipurpose Clock Generator (MCG) to run in
 *	Bypassed Low Power External (BLPE) mode. On the TWR-K60N512 board, this
 *	would be 50 MHz.
 *
 */
void MCG_BLPE() {
	// Select External Reference Clock in MCG
	MCG_C1 = MCG_C1_CLKS(2);// | MCG_C1_FRDIV(3);

	// wait for Reference clock to switch to external reference
	while (MCG_S & MCG_S_IREFST_MASK){}
	// Wait for MCGOUT to switch over to the external reference clock
	while (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x2){}

	// Transition to bypassed low power external mode
	MCG_C2 = MCG_C2_LP_MASK;
}
